//
//  AuthenticationNameViewControllrer.m
//  NiuBanJinGold
//
//  Created by zf on 15/10/12.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "AuthenticationNameViewControllrer.h"

@interface AuthenticationNameViewControllrer ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong) NSArray *array_authenticationArr;
@property (nonatomic , strong) NSMutableArray *mutableArray;
@end

@implementation AuthenticationNameViewControllrer

-(void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self getDataFromNet];
}

- (void)getDataFromNet {
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *dic_safe = @{@"userId" : GETCURRENTUSERINOBYPRAMETERES(user_userId) , @"token" : GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    [[NETWorkingUtil sharedNETWorking] zzjrMore_safeCenterByParmeteres:dic_safe transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if (!error) {
            
            if ([parsedData[@"status"] integerValue ] == 0) {
                NSDictionary *dic_result = parsedData[@"result"];
                if ([dic_result[@"authentication"]integerValue] == 0) {
                    
                  
                }else {
                    
                    NSString *name = dic_result[@"realName"];
                    NSString *idCardNo = dic_result[@"idCardNo"];
                    
                    if (name.length != 0 && idCardNo.length != 0) {
                        
                        [self.mutableArray removeAllObjects];
                        [self.mutableArray addObject:name];
                        [self.mutableArray addObject:idCardNo];
                        UITableView *tableView = (UITableView *)[self.view viewWithTag:100];
                        
                        NSIndexPath *indexPath_name = [NSIndexPath indexPathForRow:0 inSection:0];
                        
                        [tableView reloadRowsAtIndexPaths:@[indexPath_name] withRowAnimation:YES];
                        
                        NSIndexPath *indexPath_idCardNo = [NSIndexPath indexPathForRow:1 inSection:0];
                        
                        [tableView reloadRowsAtIndexPaths:@[indexPath_idCardNo] withRowAnimation:YES];

                    }
                }
                
            }else{
                
                [UsefulUtil showAlertView:parsedData[@"msg"]];
            }
        }else {
            
            [UsefulUtil showAlertView:@"遇到网络问题,请稍后重试!"];
        }
        
    }];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"实名验证";
    
    self.array_authenticationArr = @[@"姓名" , @"身份证号" ];
    
    self.mutableArray = [NSMutableArray array];
    UITableView *tableView = [[UITableView alloc]initWithFrame:
                              [UIScreen mainScreen].bounds style:UITableViewStylePlain];
    tableView.tag = 100;
    [tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    
    
    UIView *view_footView = [[UIView alloc]initWithFrame:CGRectZero];
    [tableView setTableFooterView:view_footView];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
    
   
    
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureAction)];
    [self.view addGestureRecognizer:swipeGesture];
    
}

#pragma mark -swipeGestureAction
-(void)swipeGestureAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - heightForHeaderInSection
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
       return 10;
}
#pragma mark - numberOfRowsInSection
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.mutableArray.count > 0) {
        return  self.mutableArray.count;
    }else{
      return 2;
    }
}
#pragma mark - cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"cellID";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (nil == cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
        
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = [self.array_authenticationArr objectAtIndex:indexPath.row];
    if (self.mutableArray.count > 0) {
        
        cell.detailTextLabel.text = [self.mutableArray objectAtIndex:indexPath.row];
    }
    
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
